package com.multitrack.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.multitrack.R;

/**
 *
 */
public class TestRTLActivity extends AppCompatActivity {
    private ConstraintLayout mConstraintLayout;
    private EditText subtitleEt;
    private Button menu1, menu2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vemultitrack_cv_rtl_layout);
        
        initViews();
        setupListeners();
    }

    private void initViews() {
        mConstraintLayout = findViewById(R.id.mConstraintLayout);
        subtitleEt = findViewById(R.id.subtitle_et);
        menu1 = findViewById(R.id.menu1);
        menu2 = findViewById(R.id.menu2);
    }

    private void setupListeners() {
        subtitleEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    // Check if the text contains Arabic characters
                    boolean containsArabic = s.toString().matches(".*[\\u0600-\\u06FF].*");
                    if (containsArabic) {
                        // Set RTL layout direction
                        mConstraintLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
                    } else {
                        // Set LTR layout direction
                        mConstraintLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
                    }
                }
            }
        });

        // Set click listeners for menus
        menu1.setOnClickListener(v -> {
            // Handle menu1 click
        });

        menu2.setOnClickListener(v -> {
            // Handle menu2 click
        });

    }
}
